from config import *

class Register:
	def GET(self):
		return render.register()
	
	def POST(self):
		input = web.input()
		#print input
		try:
			db.insert(TableRegister, usercode = input.usercode, username = input.username, password = input.password)
		except Exception, e:
			print e
			if 'Duplicate entry' in e[1]:
				return 0
		myvar = dict(usercode=input.usercode);
		result = db.select(TableRegister, myvar, where="usercode = $usercode")
		row = result[0]
		try:
			db.insert(TableUserInfo, idregister = row.idregister)
		except Exception, e:
			print '*' * 90 + 'register, post'
			print e
		print input.usercode, input.username, input.password
		return 1 #register success
		

class Registered:
	def GET(self):
		return render.registered()